/** 订阅或取消订阅时 计算话题列表增量 */
export const getTopicList = (
  pre: any,
  delta: any,
  isDelete?: any,
) => {
  const newTopicList = [...pre];
  const deltaTopicList = [...delta];
  // 取消订阅
  if (isDelete) {
    return {
      newTopicList: newTopicList.filter(
        (n) => !deltaTopicList.some((d) => d.topicKey === n.topicKey),
      ),
      deltaTopicList,
    };
  }
  // 订阅
  deltaTopicList.forEach((d) => {
    if (newTopicList.some((n) => n.topicKey === d.topicKey)) {
      d.used = true;
    } else {
      newTopicList.push(d);
    }
  });
  return {
    newTopicList,
    deltaTopicList: deltaTopicList.filter((d) => !d.used),
  };
};
